package com.zxy.fmmall.controller;


import com.zxy.fmmall.entity.Users;
import com.zxy.fmmall.service.UserService;
import com.zxy.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value = "提供用户的登录和注册接口",tags = "用户管理")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "String",name = "username",value = "用户登录账号",required = true),
            @ApiImplicitParam(paramType="string",name = "password",value = "用户登录密码",required = true)
    })
    @GetMapping("/login")
    public ResultVo login(String username,String password){
        return userService.checkLogin(username,password);
    }

    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",required = true),
            @ApiImplicitParam(name = "password",required = true)
    })
    @PostMapping("/regist")
    public ResultVo regist(@RequestBody Users user){
        return userService.regist(user.getUsername(),user.getPassword());
    }

    @ApiOperation("登录验证接口")
    @GetMapping("/check")
    public ResultVo check(){
        return ResultVo.ok();
    }

}
